home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / ViewCommands.cpp < prev    next >
Text File  |  1997-08-07  |  34KB  |  1,406 lines

  1. /*
  2.  *  File:       ViewCommands.cpp
  3.  *  Summary:       Command objects for manipulating views.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     4/06/97    JDJ        Updated for new style TSubPaneIterator.
  12.  *         <1>     8/29/96    JDJ        Created
  13.  */
  14.  
  15. #include "ViewCommands.h"
  16.  
  17. #include <Limits.h>
  18. #include <List.h>
  19. #include <Scrap.h>
  20.  
  21. #include <ZHandleStream.h>
  22. #include <ZMiscUtils.h>
  23. #include <ZScrap.h>
  24. #include <ZStringUtils.h>
  25. #include <ZUndoMgr.h>
  26.  
  27. #include "ViewContainer.h"
  28.  
  29.  
  30. // ===================================================================================
  31. //    class CResizePaneCommand
  32. // ===================================================================================
  33.  
  34. //---------------------------------------------------------------
  35. //
  36. // CResizePaneCommand::~CResizePaneCommand
  37. //
  38. //---------------------------------------------------------------
  39. CResizePaneCommand::~CResizePaneCommand()
  40. {
  41. }
  42.  
  43.  
  44. //---------------------------------------------------------------
  45. //
  46. // CResizePaneCommand::CResizePaneCommand (TPane*, TRect)
  47. //
  48. //---------------------------------------------------------------
  49. CResizePaneCommand::CResizePaneCommand(TPane* pane, const TRect& newFrame) : mPane(pane)
  50. {
  51.     ASSERT(pane != nil);
  52.         
  53.     mOldFrame = mPane->GetFrame();
  54.     mNewFrame = newFrame;
  55.     
  56.     TView* superView = mPane->GetSuperView();
  57.     mContainer = dynamic_cast<CViewContainer*>(superView);
  58.     while (mContainer == nil && superView != nil) {
  59.         superView = superView->GetSuperView();
  60.         mContainer = dynamic_cast<CViewContainer*>(superView);
  61.     }
  62.     ASSERT(mContainer != nil);
  63. }
  64.  
  65.  
  66. //---------------------------------------------------------------
  67. //
  68. // CResizePaneCommand::CResizePaneCommand (TPane*, TRect, TRect)
  69. //
  70. //---------------------------------------------------------------
  71. CResizePaneCommand::CResizePaneCommand(TPane* pane, const TRect& oldFrame, const TRect& newFrame) : mPane(pane)
  72. {
  73.     ASSERT(pane != nil);
  74.     ASSERT(oldFrame != newFrame);
  75.         
  76.     mOldFrame = oldFrame;
  77.     mNewFrame = newFrame;
  78.     
  79.     TView* superView = mPane->GetSuperView();
  80.     mContainer = dynamic_cast<CViewContainer*>(superView);
  81.     while (mContainer == nil && superView != nil) {
  82.         superView = superView->GetSuperView();
  83.         mContainer = dynamic_cast<CViewContainer*>(superView);
  84.     }
  85.     ASSERT(mContainer != nil);
  86. }
  87.     
  88.  
  89. //---------------------------------------------------------------
  90. //
  91. // CResizePaneCommand::GetText
  92. //
  93. //---------------------------------------------------------------
  94. string CResizePaneCommand::GetText() const
  95. {
  96.     return LoadIndString(256, 15);
  97. }
  98.  
  99.  
  100. //---------------------------------------------------------------
  101. //
  102. // CResizePaneCommand::IsValid
  103. //
  104. //---------------------------------------------------------------
  105. bool CResizePaneCommand::IsValid() const
  106. {
  107.     return mPane.TargetExists();
  108. }
  109.  
  110.  
  111. //---------------------------------------------------------------
  112. //
  113. // CResizePaneCommand::OnDo
  114. //
  115. //---------------------------------------------------------------
  116. void CResizePaneCommand::OnDo()
  117. {
  118.     mContainer->Select(nil);
  119.     
  120.     mPane->SetFrame(mNewFrame);
  121.     mContainer->Select(mPane.Get());
  122.     
  123.     mContainer->UpdateResource();
  124. }
  125.  
  126.  
  127. //---------------------------------------------------------------
  128. //
  129. // CResizePaneCommand::OnUndo
  130. //
  131. //---------------------------------------------------------------
  132. void CResizePaneCommand::OnUndo()
  133. {
  134.     mContainer->Select(nil);
  135.     
  136.     mPane->SetFrame(mOldFrame);
  137.     mContainer->Select(mPane.Get());
  138.  
  139.     mContainer->UpdateResource();
  140. }
  141.  
  142.  
  143. //---------------------------------------------------------------
  144. //
  145. // CResizePaneCommand::OnRedo
  146. //
  147. //---------------------------------------------------------------
  148. void CResizePaneCommand::OnRedo()
  149. {
  150.     mContainer->Select(nil);
  151.     
  152.     mPane->SetFrame(mNewFrame);
  153.     mContainer->Select(mPane.Get());
  154.  
  155.     mContainer->UpdateResource();
  156. }
  157.  
  158. #pragma mark -
  159.  
  160. // ===================================================================================
  161. //    class CPaneEditCommand
  162. // ===================================================================================
  163.  
  164. //---------------------------------------------------------------
  165. //
  166. // CPaneEditCommand::~CPaneEditCommand
  167. //
  168. //---------------------------------------------------------------
  169. CPaneEditCommand::~CPaneEditCommand()
  170. {
  171.     delete mPanes;
  172. }
  173.  
  174.  
  175. //---------------------------------------------------------------
  176. //
  177. // CPaneEditCommand::CPaneEditCommand (CViewContainer*, bool)
  178. //
  179. //---------------------------------------------------------------
  180. CPaneEditCommand::CPaneEditCommand(CViewContainer* container, bool addSelection)
  181. {
  182.     ASSERT(container != nil);
  183.     
  184.     mContainer = container;
  185.     
  186.     mPanes = new list<SInfo, allocator<SInfo> >;                            
  187.     
  188.     if (addSelection) {
  189.         try {
  190.             TSubPaneIterator iter = mContainer->begin(kRecursive);
  191.             while (iter != mContainer->end()) {
  192.                 TPane* pane = *iter;
  193.                 ++iter;
  194.                 
  195.                 if (mContainer->IsSelected(pane))
  196.                     mPanes->push_back(pane);
  197.             }
  198.         
  199.         } catch (...) {
  200.             delete mPanes;
  201.             throw;
  202.         }
  203.     }
  204. }
  205.  
  206.  
  207. //---------------------------------------------------------------
  208. //
  209. // CPaneEditCommand::CPaneEditCommand (CViewContainer*, TUndoMgr*, bool)
  210. //
  211. //---------------------------------------------------------------
  212. CPaneEditCommand::CPaneEditCommand(CViewContainer* container, TUndoMgr* context, bool addSelection) : TUndoableCommand(context)
  213. {
  214.     ASSERT(container != nil);
  215.     
  216.     mContainer = container;
  217.     
  218.     mPanes = new list<SInfo, allocator<SInfo> >;                            
  219.     
  220.     if (addSelection) {
  221.         try {
  222.             TSubPaneIterator iter = mContainer->begin(kRecursive);
  223.             while (iter != mContainer->end()) {
  224.                 TPane* pane = *iter;
  225.                 ++iter;
  226.                 
  227.                 if (mContainer->IsSelected(pane))
  228.                     mPanes->push_back(pane);
  229.             }
  230.         
  231.         } catch (...) {
  232.             delete mPanes;
  233.             throw;
  234.         }
  235.     }
  236. }
  237.  
  238.  
  239. //---------------------------------------------------------------
  240. //
  241. // CPaneEditCommand::IsValid
  242. //
  243. //---------------------------------------------------------------
  244. bool CPaneEditCommand::IsValid() const
  245. {
  246.     bool valid = true;
  247.     
  248.     list<SInfo, allocator<SInfo> >::const_iterator iter = mPanes->begin();
  249.     while (iter != mPanes->end() && valid) {
  250.         const SInfo& info = *iter++;
  251.         
  252.         valid = info.pane.TargetExists() && info.super.TargetExists();
  253.     }
  254.  
  255.     return valid;
  256. }
  257.  
  258. #pragma mark -
  259.  
  260. // ===================================================================================
  261. //    class CAddPanesCommand
  262. // ===================================================================================
  263.  
  264. //---------------------------------------------------------------
  265. //
  266. // CAddPanesCommand::~CAddPanesCommand
  267. //
  268. //---------------------------------------------------------------
  269. CAddPanesCommand::~CAddPanesCommand()
  270. {
  271.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  272.     while (iter != mPanes->end()) {
  273.         SInfo& info = *iter++;
  274.         
  275.         if (info.pane.TargetExists() && info.pane->GetSuperView() == nil)
  276.             delete info.pane.Get();
  277.     }
  278. }
  279.  
  280.  
  281. //---------------------------------------------------------------
  282. //
  283. // CAddPanesCommand::CAddPanesCommand (CViewContainer*, bool)
  284. //
  285. //---------------------------------------------------------------
  286. CAddPanesCommand::CAddPanesCommand(CViewContainer* container, bool addSelection) : CPaneEditCommand(container, addSelection)
  287. {
  288. }
  289.  
  290.  
  291. //---------------------------------------------------------------
  292. //
  293. // CAddPanesCommand::CAddPanesCommand (CViewContainer*, TUndoMgr*, bool)
  294. //
  295. //---------------------------------------------------------------
  296. CAddPanesCommand::CAddPanesCommand(CViewContainer* container, TUndoMgr* context, bool addSelection) : CPaneEditCommand(container, context, addSelection)
  297. {
  298. }
  299.  
  300.  
  301. //---------------------------------------------------------------
  302. //
  303. // CAddPanesCommand::OnAdd
  304. //
  305. //---------------------------------------------------------------
  306. void CAddPanesCommand::OnAdd()
  307. {
  308.     mContainer->Select(nil);
  309.     
  310.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  311.     while (iter != mPanes->end()) {
  312.         SInfo& info = *iter++;
  313.         
  314.         info.super->AddSubPane(info.pane.Get());
  315.         mContainer->Select(info.pane.Get(), true);        
  316.     }
  317.     
  318.     mContainer->UpdateResource();
  319. }
  320.  
  321.  
  322. //---------------------------------------------------------------
  323. //
  324. // CAddPanesCommand::OnRemove
  325. //
  326. //---------------------------------------------------------------
  327. void CAddPanesCommand::OnRemove()
  328. {
  329.     mContainer->Select(nil);
  330.     
  331.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  332.     while (iter != mPanes->end()) {
  333.         SInfo& info = *iter++;
  334.         
  335.         info.super->RemoveSubPane(info.pane.Get());
  336.     }
  337.     
  338.     mContainer->UpdateResource();
  339. }
  340.  
  341. #pragma mark -
  342.  
  343. // ===================================================================================
  344. //    class CAddSubPanesCommand
  345. // ===================================================================================
  346.  
  347. //---------------------------------------------------------------
  348. //
  349. // CAddSubPanesCommand::~CAddSubPanesCommand
  350. //
  351. //---------------------------------------------------------------
  352. CAddSubPanesCommand::~CAddSubPanesCommand()
  353. {
  354. }
  355.  
  356.  
  357. //---------------------------------------------------------------
  358. //
  359. // CAddSubPanesCommand::CAddSubPanesCommand
  360. //
  361. //---------------------------------------------------------------
  362. CAddSubPanesCommand::CAddSubPanesCommand(CViewContainer* container, TView* superView, TUndoMgr* context) : CAddPanesCommand(container, context, false)
  363. {
  364.     ASSERT(superView != nil);
  365.     
  366.     mSuper = superView;
  367. }
  368.  
  369.  
  370. //---------------------------------------------------------------
  371. //
  372. // CAddSubPanesCommand::AddPane 
  373. //
  374. //---------------------------------------------------------------
  375. void CAddSubPanesCommand::AddPane(TPane* pane)
  376. {
  377.     ASSERT(pane != nil);
  378.     
  379.     SInfo info(pane);
  380.     
  381.     info.super = mSuper;
  382.     
  383.     mPanes->push_back(info);
  384. }
  385.  
  386.  
  387. //---------------------------------------------------------------
  388. //
  389. // CAddSubPanesCommand::GetText
  390. //
  391. //---------------------------------------------------------------
  392. string CAddSubPanesCommand::GetText() const
  393. {
  394.     return LoadIndString(256, 11);
  395. }
  396.  
  397.  
  398. //---------------------------------------------------------------
  399. //
  400. // CAddSubPanesCommand::OnDo
  401. //
  402. //---------------------------------------------------------------
  403. void CAddSubPanesCommand::OnDo()
  404. {
  405.     this->OnAdd();
  406. }
  407.  
  408.  
  409. //---------------------------------------------------------------
  410. //
  411. // CAddSubPanesCommand::OnUndo
  412. //
  413. //---------------------------------------------------------------
  414. void CAddSubPanesCommand::OnUndo()
  415. {
  416.     this->OnRemove();
  417. }
  418.  
  419.  
  420. //---------------------------------------------------------------
  421. //
  422. // CAddSubPanesCommand::OnRedo
  423. //
  424. //---------------------------------------------------------------
  425. void CAddSubPanesCommand::OnRedo()
  426. {
  427.     this->OnAdd();
  428. }
  429.  
  430. #pragma mark -
  431.  
  432. // ===================================================================================
  433. //    class CDeletePanesCommand
  434. // ===================================================================================
  435.  
  436. //---------------------------------------------------------------
  437. //
  438. // CDeletePanesCommand::~CDeletePanesCommand
  439. //
  440. //---------------------------------------------------------------
  441. CDeletePanesCommand::~CDeletePanesCommand()
  442. {
  443. }
  444.  
  445.  
  446. //---------------------------------------------------------------
  447. //
  448. // CDeletePanesCommand::CDeletePanesCommand
  449. //
  450. //---------------------------------------------------------------
  451. CDeletePanesCommand::CDeletePanesCommand(CViewContainer* container) : CAddPanesCommand(container)
  452. {
  453. }
  454.  
  455.  
  456. //---------------------------------------------------------------
  457. //
  458. // CDeletePanesCommand::GetText
  459. //
  460. //---------------------------------------------------------------
  461. string CDeletePanesCommand::GetText() const
  462. {
  463.     return LoadIndString(256, 7);
  464. }
  465.  
  466.  
  467. //---------------------------------------------------------------
  468. //
  469. // CDeletePanesCommand::OnDo
  470. //
  471. //---------------------------------------------------------------
  472. void CDeletePanesCommand::OnDo()
  473. {
  474.     this->OnRemove();
  475. }
  476.  
  477.  
  478. //---------------------------------------------------------------
  479. //
  480. // CDeletePanesCommand::OnUndo
  481. //
  482. //---------------------------------------------------------------
  483. void CDeletePanesCommand::OnUndo()
  484. {
  485.     this->OnAdd();
  486. }
  487.  
  488.  
  489. //---------------------------------------------------------------
  490. //
  491. // CDeletePanesCommand::OnRedo
  492. //
  493. //---------------------------------------------------------------
  494. void CDeletePanesCommand::OnRedo()
  495. {
  496.     this->OnRemove();
  497. }
  498.  
  499. #pragma mark -
  500.  
  501. // ===================================================================================
  502. //    class CDuplicatePanesCommand
  503. // ===================================================================================
  504.  
  505. //---------------------------------------------------------------
  506. //
  507. // CDuplicatePanesCommand::~CDuplicatePanesCommand
  508. //
  509. //---------------------------------------------------------------
  510. CDuplicatePanesCommand::~CDuplicatePanesCommand()
  511. {
  512. }
  513.  
  514.  
  515. //---------------------------------------------------------------
  516. //
  517. // CDuplicatePanesCommand::CDuplicatePanesCommand
  518. //
  519. //---------------------------------------------------------------
  520. CDuplicatePanesCommand::CDuplicatePanesCommand(CViewContainer* container) : CAddPanesCommand(container)
  521. {
  522.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  523.     while (iter != mPanes->end()) {
  524.         SInfo& info = *iter++;
  525.         
  526.         THandle data;
  527.         
  528.         {
  529.         TOutHandleStream stream(data);                
  530.             info.pane->Externalize(stream);
  531.         }
  532.  
  533.         {
  534.         TInHandleStream stream(data);            
  535.             info.pane = TPane::Create(stream, info.super.Get());
  536.             mContainer->DecoratePane(info.pane.Get());
  537.             mContainer->Select(info.pane.Get(), true);        
  538.             
  539.             TPoint loc = info.pane->GetLocation();
  540.             info.pane->SetLocation(loc + TPoint(16, 16));
  541.  
  542.             info.super->RemoveSubPane(info.pane.Get());
  543.         }
  544.     }
  545. }
  546.  
  547.  
  548. //---------------------------------------------------------------
  549. //
  550. // CDuplicatePanesCommand::GetText
  551. //
  552. //---------------------------------------------------------------
  553. string CDuplicatePanesCommand::GetText() const
  554. {
  555.     return LoadIndString(256, 9);
  556. }
  557.  
  558.  
  559. //---------------------------------------------------------------
  560. //
  561. // CDuplicatePanesCommand::OnDo
  562. //
  563. //---------------------------------------------------------------
  564. void CDuplicatePanesCommand::OnDo()
  565. {
  566.     this->OnAdd();
  567. }
  568.  
  569.  
  570. //---------------------------------------------------------------
  571. //
  572. // CDuplicatePanesCommand::OnUndo
  573. //
  574. //---------------------------------------------------------------
  575. void CDuplicatePanesCommand::OnUndo()
  576. {
  577.     this->OnRemove();
  578. }
  579.  
  580.  
  581. //---------------------------------------------------------------
  582. //
  583. // CDuplicatePanesCommand::OnRedo
  584. //
  585. //---------------------------------------------------------------
  586. void CDuplicatePanesCommand::OnRedo()
  587. {
  588.     this->OnAdd();
  589. }
  590.  
  591. #pragma mark -
  592.  
  593. // ===================================================================================
  594. //    class CMovePanesCommand
  595. // ===================================================================================
  596.  
  597. //---------------------------------------------------------------
  598. //
  599. // CMovePanesCommand::~CMovePanesCommand
  600. //
  601. //---------------------------------------------------------------
  602. CMovePanesCommand::~CMovePanesCommand()
  603. {
  604. }
  605.  
  606.  
  607. //---------------------------------------------------------------
  608. //
  609. // CMovePanesCommand::CMovePanesCommand 
  610. //
  611. //---------------------------------------------------------------
  612. CMovePanesCommand::CMovePanesCommand(CViewContainer* container, TView* newSuper, TUndoMgr* context) : CPaneEditCommand(container, context, false)
  613. {
  614.     ASSERT(newSuper != nil);
  615.     
  616.     mNewSuper = newSuper;
  617. }
  618.  
  619.  
  620. //---------------------------------------------------------------
  621. //
  622. // CMovePanesCommand::AddPane 
  623. //
  624. //---------------------------------------------------------------
  625. void CMovePanesCommand::AddPane(TPane* pane, const TPoint& newLoc)
  626. {
  627.     ASSERT(pane != nil);
  628.     
  629.     SInfo info(pane);
  630.     
  631.     info.newInfo.loc = newLoc;
  632.     
  633.     mPanes->push_back(info);
  634. }
  635.  
  636.  
  637. //---------------------------------------------------------------
  638. //
  639. // CMovePanesCommand::GetText
  640. //
  641. //---------------------------------------------------------------
  642. string CMovePanesCommand::GetText() const
  643. {
  644.     return LoadIndString(256, 13);
  645. }
  646.  
  647.  
  648. //---------------------------------------------------------------
  649. //
  650. // CMovePanesCommand::OnDo
  651. //
  652. //---------------------------------------------------------------
  653. void CMovePanesCommand::OnDo()
  654. {
  655.     this->OnRedo();
  656. }
  657.  
  658.  
  659. //---------------------------------------------------------------
  660. //
  661. // CMovePanesCommand::OnUndo
  662. //
  663. //---------------------------------------------------------------
  664. void CMovePanesCommand::OnUndo()
  665. {
  666.     mContainer->Select(nil);
  667.     
  668.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  669.     while (iter != mPanes->end()) {
  670.         SInfo& info = *iter++;
  671.         
  672.         if (info.super != mNewSuper) {
  673.             mNewSuper->RemoveSubPane(info.pane.Get());
  674.  
  675.             info.super->AddSubPane(info.pane.Get());
  676.         }
  677.  
  678.         info.pane->SetLocation(info.oldInfo.loc);
  679.         mContainer->Select(info.pane.Get(), true);        
  680.     }
  681.     
  682.     mContainer->UpdateResource();
  683. }
  684.  
  685.  
  686. //---------------------------------------------------------------
  687. //
  688. // CMovePanesCommand::OnRedo
  689. //
  690. //---------------------------------------------------------------
  691. void CMovePanesCommand::OnRedo()
  692. {
  693.     mContainer->Select(nil);
  694.     
  695.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  696.     while (iter != mPanes->end()) {
  697.         SInfo& info = *iter++;
  698.         
  699.         if (info.super != mNewSuper) {
  700.             info.super->RemoveSubPane(info.pane.Get());
  701.  
  702.             mNewSuper->AddSubPane(info.pane.Get());
  703.         }
  704.  
  705.         info.pane->SetLocation(info.newInfo.loc);
  706.         mContainer->Select(info.pane.Get(), true);        
  707.     }
  708.     
  709.     mContainer->UpdateResource();
  710. }
  711.  
  712. #pragma mark -
  713.  
  714. // ===================================================================================
  715. //    class CCopyPanesCommand
  716. // ===================================================================================
  717.  
  718. //---------------------------------------------------------------
  719. //
  720. // CCopyPanesCommand::~CCopyPanesCommand
  721. //
  722. //---------------------------------------------------------------
  723. CCopyPanesCommand::~CCopyPanesCommand()
  724. {
  725. }
  726.  
  727.  
  728. //---------------------------------------------------------------
  729. //
  730. // CCopyPanesCommand::CCopyPanesCommand
  731. //
  732. //---------------------------------------------------------------
  733. CCopyPanesCommand::CCopyPanesCommand(CViewContainer* container) : CAddPanesCommand(container)
  734. {
  735. }
  736.  
  737.  
  738. //---------------------------------------------------------------
  739. //
  740. // CCopyPanesCommand::GetText
  741. //
  742. //---------------------------------------------------------------
  743. string CCopyPanesCommand::GetText() const
  744. {
  745.     return LoadIndString(256, 3);
  746. }
  747.  
  748.  
  749. //---------------------------------------------------------------
  750. //
  751. // CCopyPanesCommand::OnDo
  752. //
  753. //---------------------------------------------------------------
  754. void CCopyPanesCommand::OnDo()
  755. {
  756.     TOutHandleStream stream;
  757.         
  758.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  759.     while (iter != mPanes->end()) {
  760.         SInfo& info = *iter++;
  761.         TPane* pane = info.pane.Get();
  762.                 
  763.         {
  764.         TOutHandleStream tempStream;                
  765.             pane->Externalize(tempStream);
  766.  
  767.             SResource rsrc(kIndeterminateID, "", tempStream.GetHandle());
  768.             stream << rsrc;
  769.         }
  770.     }
  771.     
  772.     mOldScrap = ::GetScrap();
  773.     ::ZeroScrap();
  774.     ::PutScrap('View', stream.GetHandle());
  775.     mNewScrap = ::GetScrap();
  776. }
  777.  
  778.  
  779. //---------------------------------------------------------------
  780. //
  781. // CCopyPanesCommand::OnUndo
  782. //
  783. //---------------------------------------------------------------
  784. void CCopyPanesCommand::OnUndo()
  785. {
  786.     ::SetScrap(mOldScrap);
  787. }
  788.  
  789.  
  790. //---------------------------------------------------------------
  791. //
  792. // CCopyPanesCommand::OnRedo
  793. //
  794. //---------------------------------------------------------------
  795. void CCopyPanesCommand::OnRedo()
  796. {
  797.     ::SetScrap(mNewScrap);
  798. }
  799.  
  800. #pragma mark -
  801.  
  802. // ===================================================================================
  803. //    class CCutPanesCommand
  804. // ===================================================================================
  805.  
  806. //---------------------------------------------------------------
  807. //
  808. // CCutPanesCommand::~CCutPanesCommand
  809. //
  810. //---------------------------------------------------------------
  811. CCutPanesCommand::~CCutPanesCommand()
  812. {
  813. }
  814.  
  815.  
  816. //---------------------------------------------------------------
  817. //
  818. // CCutPanesCommand::CCutPanesCommand
  819. //
  820. //---------------------------------------------------------------
  821. CCutPanesCommand::CCutPanesCommand(CViewContainer* container) : CCopyPanesCommand(container)
  822. {
  823. }
  824.  
  825.  
  826. //---------------------------------------------------------------
  827. //
  828. // CCutPanesCommand::GetText
  829. //
  830. //---------------------------------------------------------------
  831. string CCutPanesCommand::GetText() const
  832. {
  833.     return LoadIndString(256, 1);
  834. }
  835.  
  836.  
  837. //---------------------------------------------------------------
  838. //
  839. // CCutPanesCommand::OnDo
  840. //
  841. //---------------------------------------------------------------
  842. void CCutPanesCommand::OnDo()
  843. {
  844.     Inherited::OnDo();
  845.     
  846.     this->OnRemove();
  847. }
  848.  
  849.  
  850. //---------------------------------------------------------------
  851. //
  852. // CCutPanesCommand::OnUndo
  853. //
  854. //---------------------------------------------------------------
  855. void CCutPanesCommand::OnUndo()
  856. {
  857.     Inherited::OnUndo();
  858.     
  859.     this->OnAdd();
  860. }
  861.  
  862.  
  863. //---------------------------------------------------------------
  864. //
  865. // CCutPanesCommand::OnRedo
  866. //
  867. //---------------------------------------------------------------
  868. void CCutPanesCommand::OnRedo()
  869. {
  870.     Inherited::OnRedo();
  871.     
  872.     this->OnRemove();
  873. }
  874.  
  875. #pragma mark -
  876.  
  877. // ===================================================================================
  878. //    class CPastePanesCommand
  879. // ===================================================================================
  880.  
  881. //---------------------------------------------------------------
  882. //
  883. // CPastePanesCommand::~CPastePanesCommand
  884. //
  885. //---------------------------------------------------------------
  886. CPastePanesCommand::~CPastePanesCommand()
  887. {
  888. }
  889.  
  890.  
  891. //---------------------------------------------------------------
  892. //
  893. // CPastePanesCommand::CPastePanesCommand
  894. //
  895. //---------------------------------------------------------------
  896. CPastePanesCommand::CPastePanesCommand(CViewContainer* container, TView* superView) : CAddPanesCommand(container, false)
  897. {
  898.     ASSERT(superView != nil);
  899.     
  900.     mSuper = superView;
  901. }
  902.  
  903.  
  904. //---------------------------------------------------------------
  905. //
  906. // CPastePanesCommand::GetText
  907. //
  908. //---------------------------------------------------------------
  909. string CPastePanesCommand::GetText() const
  910. {
  911.     return LoadIndString(256, 5);
  912. }
  913.  
  914.  
  915. //---------------------------------------------------------------
  916. //
  917. // CPastePanesCommand::OnDo
  918. //
  919. //---------------------------------------------------------------
  920. void CPastePanesCommand::OnDo()
  921. {
  922.     mContainer->Select(nil);
  923.     
  924.     THandle data = ::GetScrap('View');
  925.     TInHandleStream stream(data);
  926.     
  927.     while (!stream.AtEnd()) {
  928.         SResource rsrc;
  929.         stream >> rsrc;
  930.         
  931.         {
  932.         TInHandleStream tempStream(rsrc.data);                
  933.             TPane* pane = TPane::Create(tempStream, mSuper);
  934.             mContainer->DecoratePane(pane);
  935.             mContainer->Select(pane);    
  936.  
  937.             mPanes->push_back(pane);
  938.         }
  939.     }
  940.  
  941.     mContainer->UpdateResource();
  942. }
  943.  
  944.  
  945. //---------------------------------------------------------------
  946. //
  947. // CPastePanesCommand::OnUndo
  948. //
  949. //---------------------------------------------------------------
  950. void CPastePanesCommand::OnUndo()
  951. {
  952.     this->OnRemove();
  953. }
  954.  
  955.  
  956. //---------------------------------------------------------------
  957. //
  958. // CPastePanesCommand::OnRedo
  959. //
  960. //---------------------------------------------------------------
  961. void CPastePanesCommand::OnRedo()
  962. {
  963.     this->OnAdd();
  964. }
  965.  
  966. #pragma mark -
  967.  
  968. // ===================================================================================
  969. //    class COffsetPanesCommand
  970. // ===================================================================================
  971.  
  972. //---------------------------------------------------------------
  973. //
  974. // COffsetPanesCommand::~COffsetPanesCommand
  975. //
  976. //---------------------------------------------------------------
  977. COffsetPanesCommand::~COffsetPanesCommand()
  978. {
  979. }
  980.  
  981.  
  982. //---------------------------------------------------------------
  983. //
  984. // COffsetPanesCommand::COffsetPanesCommand
  985. //
  986. //---------------------------------------------------------------
  987. COffsetPanesCommand::COffsetPanesCommand(CViewContainer* container) : CPaneEditCommand(container)
  988. {
  989. }
  990.  
  991.  
  992. //---------------------------------------------------------------
  993. //
  994. // COffsetPanesCommand::OnDo
  995. //
  996. //---------------------------------------------------------------
  997. void COffsetPanesCommand::OnDo()
  998. {
  999.     this->OnRedo();
  1000. }
  1001.  
  1002.  
  1003. //---------------------------------------------------------------
  1004. //
  1005. // COffsetPanesCommand::OnUndo
  1006. //
  1007. //---------------------------------------------------------------
  1008. void COffsetPanesCommand::OnUndo()
  1009. {
  1010.     mContainer->Select(nil);
  1011.     
  1012.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1013.     while (iter != mPanes->end()) {
  1014.         SInfo& info = *iter++;
  1015.         
  1016.         info.pane->SetLocation(info.oldInfo.loc);
  1017.         mContainer->Select(info.pane.Get(), true);        
  1018.     }
  1019.     
  1020.     mContainer->UpdateResource();
  1021. }
  1022.  
  1023.  
  1024. //---------------------------------------------------------------
  1025. //
  1026. // COffsetPanesCommand::OnRedo
  1027. //
  1028. //---------------------------------------------------------------
  1029. void COffsetPanesCommand::OnRedo()
  1030. {
  1031.     mContainer->Select(nil);
  1032.     
  1033.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1034.     while (iter != mPanes->end()) {
  1035.         SInfo& info = *iter++;
  1036.         
  1037.         info.pane->SetLocation(info.newInfo.loc);
  1038.         mContainer->Select(info.pane.Get(), true);        
  1039.     }
  1040.     
  1041.     mContainer->UpdateResource();
  1042. }
  1043.  
  1044. #pragma mark -
  1045.  
  1046. // ===================================================================================
  1047. //    class CNudgePaneCommand
  1048. // ===================================================================================
  1049.  
  1050. //---------------------------------------------------------------
  1051. //
  1052. // CNudgePaneCommand::~CNudgePaneCommand
  1053. //
  1054. //---------------------------------------------------------------
  1055. CNudgePaneCommand::~CNudgePaneCommand()
  1056. {
  1057. }
  1058.  
  1059.  
  1060. //---------------------------------------------------------------
  1061. //
  1062. // CNudgePaneCommand::CNudgePaneCommand
  1063. //
  1064. //---------------------------------------------------------------
  1065. CNudgePaneCommand::CNudgePaneCommand(CViewContainer* container, char key) : COffsetPanesCommand(container)
  1066. {
  1067.     ASSERT(key == kLeftArrowChar || key == kRightArrowChar || key == kUpArrowChar || key == kDownArrowChar);
  1068.     
  1069.     mKey      = key;
  1070.     mExecuted = false;
  1071. }
  1072.  
  1073.  
  1074. //---------------------------------------------------------------
  1075. //
  1076. // CNudgePaneCommand::CanNudge
  1077. //
  1078. //---------------------------------------------------------------
  1079. bool CNudgePaneCommand::CanNudge(CViewContainer* container, char key) const
  1080. {
  1081.     bool can = false;
  1082.     
  1083.     if (container == mContainer && key == mKey) {
  1084.         if (TUndoMgr::GetContext()->GetUndoCommand() == this) {
  1085.             if (!TUndoMgr::GetContext()->CanRedo()) {
  1086.                 if (!mExecuted) {
  1087.                     can = true;
  1088.                     
  1089.                     TSubPaneIterator iter = mContainer->begin(kRecursive); // make sure the selection hasn't changed
  1090.                     while (iter != mContainer->end() && can) {
  1091.                         TPane* pane = *iter;
  1092.                         ++iter;
  1093.                         
  1094.                         if (mContainer->IsSelected(pane)) {
  1095.                             if (find(mPanes->begin(), mPanes->end(), pane) == mPanes->end())
  1096.                                 can = false;
  1097.                                 
  1098.                         } else {
  1099.                             if (find(mPanes->begin(), mPanes->end(), pane) != mPanes->end())
  1100.                                 can = false;
  1101.                         }
  1102.                     }
  1103.                 }
  1104.             }
  1105.         }
  1106.     }
  1107.         
  1108.     return can;
  1109. }
  1110.  
  1111.  
  1112. //---------------------------------------------------------------
  1113. //
  1114. // CNudgePaneCommand::Nudge
  1115. //
  1116. //---------------------------------------------------------------
  1117. void CNudgePaneCommand::Nudge()
  1118. {
  1119.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1120.     while (iter != mPanes->end()) {
  1121.         SInfo& info = *iter++;
  1122.         
  1123.         TPoint delta = kZeroPt;
  1124.         
  1125.         switch (mKey) {
  1126.             case kLeftArrowChar:
  1127.                 delta.h = -1;
  1128.                 break;
  1129.                 
  1130.             case kRightArrowChar:
  1131.                 delta.h = +1;
  1132.                 break;
  1133.                 
  1134.             case kUpArrowChar:
  1135.                 delta.v = -1;
  1136.                 break;
  1137.                 
  1138.             case kDownArrowChar:
  1139.                 delta.v = +1;
  1140.                 break;
  1141.         }
  1142.         
  1143.         info.newInfo.loc += delta;
  1144.         
  1145.         info.pane->SetLocation(info.newInfo.loc);
  1146.     }
  1147. }
  1148.  
  1149.  
  1150. //---------------------------------------------------------------
  1151. //
  1152. // CNudgePaneCommand::GetText
  1153. //
  1154. //---------------------------------------------------------------
  1155. string CNudgePaneCommand::GetText() const
  1156. {
  1157.     return LoadIndString(256, 23);
  1158. }
  1159.  
  1160.  
  1161. //---------------------------------------------------------------
  1162. //
  1163. // CNudgePaneCommand::OnDo
  1164. //
  1165. //---------------------------------------------------------------
  1166. void CNudgePaneCommand::OnDo()
  1167. {
  1168.     // handled by Nudge
  1169. }
  1170.  
  1171.  
  1172. //---------------------------------------------------------------
  1173. //
  1174. // CNudgePaneCommand::OnUndo
  1175. //
  1176. //---------------------------------------------------------------
  1177. void CNudgePaneCommand::OnUndo()
  1178. {
  1179.     Inherited::OnUndo();
  1180.  
  1181.     mExecuted = true;
  1182. }
  1183.  
  1184.  
  1185. //---------------------------------------------------------------
  1186. //
  1187. // CNudgePaneCommand::OnRedo
  1188. //
  1189. //---------------------------------------------------------------
  1190. void CNudgePaneCommand::OnRedo()
  1191. {
  1192.     Inherited::OnRedo();
  1193.  
  1194.     mExecuted = true;
  1195. }
  1196.  
  1197. #pragma mark -
  1198.  
  1199. // ===================================================================================
  1200. //    class CAlignLeftCommand
  1201. // ===================================================================================
  1202.  
  1203. //---------------------------------------------------------------
  1204. //
  1205. // CAlignLeftCommand::~CAlignLeftCommand
  1206. //
  1207. //---------------------------------------------------------------
  1208. CAlignLeftCommand::~CAlignLeftCommand()
  1209. {
  1210. }
  1211.  
  1212.  
  1213. //---------------------------------------------------------------
  1214. //
  1215. // CAlignLeftCommand::CAlignLeftCommand
  1216. //
  1217. //---------------------------------------------------------------
  1218. CAlignLeftCommand::CAlignLeftCommand(CViewContainer* container) : COffsetPanesCommand(container)
  1219. {
  1220.     short peg = SHRT_MAX;
  1221.     
  1222.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1223.     while (iter != mPanes->end()) {
  1224.         SInfo& info = *iter++;
  1225.         
  1226.         if (info.oldInfo.loc.h < peg)
  1227.             peg = info.oldInfo.loc.h;
  1228.     }
  1229.  
  1230.     iter = mPanes->begin();
  1231.     while (iter != mPanes->end()) {
  1232.         SInfo& info = *iter++;
  1233.         
  1234.         info.newInfo.loc.h = peg;
  1235.     }
  1236. }
  1237.  
  1238.  
  1239. //---------------------------------------------------------------
  1240. //
  1241. // CAlignLeftCommand::GetText
  1242. //
  1243. //---------------------------------------------------------------
  1244. string CAlignLeftCommand::GetText() const
  1245. {
  1246.     return LoadIndString(256, 24);
  1247. }
  1248.  
  1249. #pragma mark -
  1250.  
  1251. // ===================================================================================
  1252. //    class CAlignRightCommand
  1253. // ===================================================================================
  1254.  
  1255. //---------------------------------------------------------------
  1256. //
  1257. // CAlignRightCommand::~CAlignRightCommand
  1258. //
  1259. //---------------------------------------------------------------
  1260. CAlignRightCommand::~CAlignRightCommand()
  1261. {
  1262. }
  1263.  
  1264.  
  1265. //---------------------------------------------------------------
  1266. //
  1267. // CAlignRightCommand::CAlignRightCommand
  1268. //
  1269. //---------------------------------------------------------------
  1270. CAlignRightCommand::CAlignRightCommand(CViewContainer* container) : COffsetPanesCommand(container)
  1271. {
  1272.     short peg = SHRT_MIN;
  1273.     
  1274.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1275.     while (iter != mPanes->end()) {
  1276.         SInfo& info = *iter++;
  1277.         
  1278.         if (info.oldInfo.loc.h > peg)
  1279.             peg = info.oldInfo.loc.h;
  1280.     }
  1281.  
  1282.     iter = mPanes->begin();
  1283.     while (iter != mPanes->end()) {
  1284.         SInfo& info = *iter++;
  1285.         
  1286.         info.newInfo.loc.h = peg;
  1287.     }
  1288. }
  1289.  
  1290.  
  1291. //---------------------------------------------------------------
  1292. //
  1293. // CAlignRightCommand::GetText
  1294. //
  1295. //---------------------------------------------------------------
  1296. string CAlignRightCommand::GetText() const
  1297. {
  1298.     return LoadIndString(256, 25);
  1299. }
  1300.  
  1301. #pragma mark -
  1302.  
  1303. // ===================================================================================
  1304. //    class CAlignTopCommand
  1305. // ===================================================================================
  1306.  
  1307. //---------------------------------------------------------------
  1308. //
  1309. // CAlignTopCommand::~CAlignTopCommand
  1310. //
  1311. //---------------------------------------------------------------
  1312. CAlignTopCommand::~CAlignTopCommand()
  1313. {
  1314. }
  1315.  
  1316.  
  1317. //---------------------------------------------------------------
  1318. //
  1319. // CAlignTopCommand::CAlignTopCommand
  1320. //
  1321. //---------------------------------------------------------------
  1322. CAlignTopCommand::CAlignTopCommand(CViewContainer* container) : COffsetPanesCommand(container)
  1323. {
  1324.     short peg = SHRT_MAX;
  1325.     
  1326.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1327.     while (iter != mPanes->end()) {
  1328.         SInfo& info = *iter++;
  1329.         
  1330.         if (info.oldInfo.loc.v < peg)
  1331.             peg = info.oldInfo.loc.v;
  1332.     }
  1333.  
  1334.     iter = mPanes->begin();
  1335.     while (iter != mPanes->end()) {
  1336.         SInfo& info = *iter++;
  1337.         
  1338.         info.newInfo.loc.v = peg;
  1339.     }
  1340. }
  1341.  
  1342.  
  1343. //---------------------------------------------------------------
  1344. //
  1345. // CAlignTopCommand::GetText
  1346. //
  1347. //---------------------------------------------------------------
  1348. string CAlignTopCommand::GetText() const
  1349. {
  1350.     return LoadIndString(256, 26);
  1351. }
  1352.  
  1353. #pragma mark -
  1354.  
  1355. // ===================================================================================
  1356. //    class CAlignBottomCommand
  1357. // ===================================================================================
  1358.  
  1359. //---------------------------------------------------------------
  1360. //
  1361. // CAlignBottomCommand::~CAlignBottomCommand
  1362. //
  1363. //---------------------------------------------------------------
  1364. CAlignBottomCommand::~CAlignBottomCommand()
  1365. {
  1366. }
  1367.  
  1368.  
  1369. //---------------------------------------------------------------
  1370. //
  1371. // CAlignBottomCommand::CAlignBottomCommand
  1372. //
  1373. //---------------------------------------------------------------
  1374. CAlignBottomCommand::CAlignBottomCommand(CViewContainer* container) : COffsetPanesCommand(container)
  1375. {
  1376.     short peg = SHRT_MIN;
  1377.     
  1378.     list<SInfo, allocator<SInfo> >::iterator iter = mPanes->begin();
  1379.     while (iter != mPanes->end()) {
  1380.         SInfo& info = *iter++;
  1381.         
  1382.         if (info.oldInfo.loc.v > peg)
  1383.             peg = info.oldInfo.loc.v;
  1384.     }
  1385.  
  1386.     iter = mPanes->begin();
  1387.     while (iter != mPanes->end()) {
  1388.         SInfo& info = *iter++;
  1389.         
  1390.         info.newInfo.loc.v = peg;
  1391.     }
  1392. }
  1393.  
  1394.  
  1395. //---------------------------------------------------------------
  1396. //
  1397. // CAlignBottomCommand::GetText
  1398. //
  1399. //---------------------------------------------------------------
  1400. string CAlignBottomCommand::GetText() const
  1401. {
  1402.     return LoadIndString(256, 27);
  1403. }
  1404.  
  1405.  
  1406.